package linkedList;

import java.util.HashSet;
import java.util.Set;

public class QuestionOne {
    //判断链表是否有环  是返回true
    public boolean hasCycle(ListNode head) {
        Set<ListNode> map = new HashSet<ListNode>();
        while (head != null) {
            if (!map.add(head)) {
                return true;
            }
            head = head.next;
        }
        return false;

    }


}

